package com.buyouchina.web.filter;

import java.io.IOException;


import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.buyouchina.bean.privilege.User;
import com.buyouchina.utils.WebUtil;


/*
 * 员工登陆校验，如有未登录不能进入以control开头的目录
 */
public class UserValidateFilter implements Filter {

	public void destroy() {
		// TODO Auto-generated method stub

	}

	public void doFilter(ServletRequest req, ServletResponse res,
			FilterChain filterChain) throws IOException, ServletException {
		HttpServletRequest request = (HttpServletRequest)req;
		User user = WebUtil.getUser(request);
		if(user == null){
			if(user==null){
				HttpServletResponse response = (HttpServletResponse) res; 
				response.sendRedirect(request.getContextPath()+"/Logon.action");
				return ;
			}
		}
		filterChain.doFilter(req, res);
	}

	public void init(FilterConfig arg0) throws ServletException {
	}

}
